package adapter;

import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tiantong.aibilian.R;
import com.tiantong.aibilian.model.MyData;

import java.util.List;

public class DataAdapter extends BaseAdapter {
    private Context mContext;
    private List<MyData> mBluetoothDevices;


    public DataAdapter(Context mContext, List<MyData> bluetoothDevices) {
        this.mContext = mContext;
        this.mBluetoothDevices = bluetoothDevices;

    }

    @Override
    public int getCount() {
        return mBluetoothDevices.size();
    }

    @Override
    public Object getItem(int position) {
        return mBluetoothDevices.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.data_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        MyData device = (MyData) getItem(position);
        viewHolder.txttime.setText(device.getTime());
        viewHolder.txttype.setText(device.getType());
        viewHolder.txtvalue.setText(device.getValue());
        return convertView;
    }


    class ViewHolder {
        public TextView txttype;
        public TextView txtvalue;
        public TextView txttime;
        public ViewHolder(View view) {
            txttype = view.findViewById(R.id.txttype);
            txtvalue =  view.findViewById(R.id.txtvalue);
            txttime=view.findViewById(R.id.txttime);
        }
    }
}
